package cn.ultrarisk.scadmin.manager.biz.common.entity;

import cn.ultrarisk.mybatis.extension.annotation.Table;
import cn.ultrarisk.scadmin.manager.util.CollectionUtil;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**
 * 数据字典实体类
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/14
 * @since V1.0
 */
@Table(table = "dict", idColumn = Dict.ID, autoIncrement = true)
public class Dict implements Serializable {
    private static final long serialVersionUID = -3536564342967979043L;

    public static final String SOLR_COLLECTION_EXPIRED_DAY = "solr.collection.expired.day";
    public static final String SOLR_NODE_EXPIRED_DAY = "solr.node.expired.day";
    public static final String SOLR_MONITOR_EXPIRED_HOUR = "solr.monitor.expired.hour";
    public static final String ZK_BACKUP_EXPIRED_DAY = "zk.backup.expired.day";
    public static final String ERROR_LOG_EXPIRED_DAY = "errorlog.expired.day";
    public static final String SLOW_LOG_EXPIRED_DAY = "slowlog.expired.day";
    public static final String OPERATE_LOG_EXPIRED_DAY = "operatelog.expired.day";
    public static final String SCHEDULER_LOG_EXPIRED_DAY = "schedulerlog.expired.day";

    public static final String TYPE_BOOLEAN = "boolean";
    public static final String TYPE_INT = "int";
    public static final String TYPE_LONG = "long";
    public static final String TYPE_DOUBLE = "double";
    public static final String TYPE_STRING = "string";
    public static final List<String> TYPE_ALL = CollectionUtil.asList(TYPE_BOOLEAN, TYPE_INT, TYPE_LONG, TYPE_DOUBLE, TYPE_STRING);

    public static final Integer LEVEL_SYSTEM = 1;
    public static final Integer LEVEL_USER = 2;
    public static final List<Integer> LEVEL_ALL = CollectionUtil.asList(LEVEL_SYSTEM, LEVEL_USER);


    public final static String ID = "id";
    public final static String NAME = "name";
    public final static String TYPE = "type";
    public final static String VALUE = "value";
    public final static String LEVEL = "level";
    public final static String REMARK = "remark";

    public static final Map<String, String> COLUMN_PROPERTY_MAP = new LinkedHashMap<String, String>();

    static {
        COLUMN_PROPERTY_MAP.put(ID, "id");
        COLUMN_PROPERTY_MAP.put(NAME, "name");
        COLUMN_PROPERTY_MAP.put(TYPE, "type");
        COLUMN_PROPERTY_MAP.put(VALUE, "value");
        COLUMN_PROPERTY_MAP.put(LEVEL, "level");
        COLUMN_PROPERTY_MAP.put(REMARK, "remark");
    }

    /**
     * 编号
     */
    private Integer id;
    /**
     * 名称
     */
    private String name;
    /**
     * 类型
     */
    private String type;
    /**
     * 值
     */
    private String value;
    /**
     * 级别，系统级别的无法删除
     */
    private Integer level;
    /**
     * 描述
     */
    private String remark;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Boolean getBooleanValue() {
        return (TYPE_BOOLEAN.equals(this.type) && this.value != null) ? Boolean.parseBoolean(this.value) : null;
    }

    public Integer getIntValue() {
        return (TYPE_INT.equals(this.type) && this.value != null) ? Integer.parseInt(this.value) : null;
    }

    public Long getLongValue() {
        return (TYPE_LONG.equals(this.type) && this.value != null) ? Long.parseLong(this.value) : null;
    }

    public Double getDoubleValue() {
        return (TYPE_DOUBLE.equals(this.type) && this.value != null) ? Double.parseDouble(this.value) : null;
    }

    public String getStringValue() {
        return this.getValue();
    }
}